<template>
  <el-dialog
      v-model="scmiAddWinDialogVisible"
      title="新增点检保养项目"
      width="60%"
      @close="handleClose"
      draggable
      center
  >
    <template #default>
      <el-form :model="newScmi">
        <el-form-item label="项目编码">
          <el-input v-model="newScmi.scmiEncode"/>
        </el-form-item>
        <el-form-item label="项目名称">
          <el-input v-model="newScmi.scmiName"/>
        </el-form-item>
        <el-form-item label="项目类型">
          <el-radio-group v-model="newScmi.scmiType">
            <el-radio :value="1" size="large">设备点检</el-radio>
            <el-radio :value="2" size="large">设备保养</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="是否启用">
          <el-radio-group v-model="newScmi.scmiStatus">
            <el-radio :value="1" size="large">是</el-radio>
            <el-radio :value="2" size="large">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="项目内容">
          <el-input type="textarea" v-model="newScmi.scmiContent"/>
        </el-form-item>
        <el-form-item label="标准">
          <el-input type="textarea" v-model="newScmi.scmiStandard"/>
        </el-form-item>
        <el-form-item label="备注">
          <el-input type="textarea" v-model="newScmi.scmiRemark"/>
        </el-form-item>
      </el-form>
    </template>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="cancel">取消</el-button>
        <el-button type="primary" @click="addScmiSubmit">提交</el-button>
      </div>
    </template>
  </el-dialog>
</template>
<script setup>
import {ref, watch} from "vue";
import deviceRequest from "@/api/device.js";
import scmiRequest from "@/api/scmi.js";
let newScmi = ref({});
const props = defineProps(['flag']);
const emits = defineEmits(['cancelAdd','addComplete'])
let scmiAddWinDialogVisible = ref(false);

/**
 * 关闭窗体前的回调函数
 */
function handleClose(){
  newScmi = ref({});
  emits("cancelAdd");
}
function cancel(){
  newScmi = ref({});
  emits("cancelAdd");
}
/**
 * 新增点检项目的提交按钮事件
 */
function addScmiSubmit() {
  scmiRequest.insertScmi(newScmi.value, res => {
    emits("addComplete");
    scmiAddWinDialogVisible.value = false;
  })
}

// 属性侦听
watch(() => props.flag, () => {
  scmiAddWinDialogVisible.value = props.flag === 1;
});
</script>
<style scoped>

</style>